﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VICC_PRULES
    {
        public void SetUpNewRow(ref DataRow dwReturn, DataRow dwInput = null)
        {

            switch (app.company)
            {
                default:
                case "YGR":
                    #region====YGR======
                    dwReturn["ROWNID"] = "0";
                    dwReturn["PLANID"] = "YGR01";
                    dwReturn["RGROUP"] = "10";
                    dwReturn["RULEID"] = "1";
                    dwReturn["ARTSTAGE"] = "S";
                    dwReturn["ORDERNUM"] = "YGR01";
                    dwReturn["ART"] = "ART";
                    dwReturn["COLOR"] = "COLOR";
                    dwReturn["FINISH"] = "FINISH";
                    dwReturn["AUFTYP"] = "ÏúÊÛµ¥";
                    dwReturn["QTYEND"] = "1000";
                    dwReturn["QTYENDDES"] = "¶©µ¥Á¿";
                    dwReturn["LEADTIME"] = "7";
                    dwReturn["DELDATE"] = "20141201";
                    dwReturn["STARTDATE"] = "20141201";
                    dwReturn["UMS"] = "KG";
                    dwReturn["UNITNUM"] = "1";
                    dwReturn["UNDES"] = "";
                    dwReturn["UNITQTY"] = "0";
                    dwReturn["UQDES"] = "";
                    dwReturn["TTENDS"] = "0";
                    dwReturn["UENDS"] = "0";
                    dwReturn["R01"] = "0";
                    dwReturn["R01DES"] = "01";
                    dwReturn["R02"] = "0";
                    dwReturn["R02DES"] = "01";
                    dwReturn["F01"] = "0";
                    dwReturn["F01DES"] = "BZL ";
                    dwReturn["F02"] = "0";
                    dwReturn["F02DES"] = "0";
                    dwReturn["JNUM"] = "0";
                    dwReturn["JNUMDES"] = "0";
                    dwReturn["JWASTGE"] = "0";
                    dwReturn["JWASTAGEDES"] = "0";
                    dwReturn["QTYMAT"] = "1050";
                    dwReturn["REMARK"] = "³ÉÆ·ÐèÇó";
                    dwReturn["VKPQTY"] = "0";
                    #endregion
                    break;
            }
            INTEXDBC.MapData(true, ref dwReturn, dwInput);
        }
        public void InsertICC_PRULES(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                default:
                    or1.CommandText = "INSERT INTO ICC_PRULES ( ROWNID,PLANID,RGROUP,RULEID,ARTSTAGE,ORDERNUM,ART,COLOR,FINISH,AUFTYP,QTYEND,QTYENDDES,LEADTIME,DELDATE,STARTDATE,UMS,UNITNUM,UNDES,UNITQTY,UQDES,TTENDS,UENDS,R01,R01DES,R02,R02DES,F01,F01DES,F02,F02DES,JNUM,JNUMDES,JWASTGE,JWASTAGEDES,QTYMAT,REMARK,VKPQTY,P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13,P14,P15,P16,P17,P18,P19,P20,P21,P22,P23,P24,P25,P26,P27,P28,P29)"
                    + " VALUES (:ROWNID:,:PLANID:,:RGROUP:,:RULEID:,:ARTSTAGE:,:ORDERNUM:,:ART:,:COLOR:,:FINISH:,:AUFTYP:,:QTYEND:,:QTYENDDES:,:LEADTIME:,:DELDATE:,:STARTDATE:,:UMS:,:UNITNUM:,:UNDES:,:UNITQTY:,:UQDES:,:TTENDS:,:UENDS:,:R01:,:R01DES:,:R02:,:R02DES:,:F01:,:F01DES:,:F02:,:F02DES:,:JNUM:,:JNUMDES:,:JWASTGE:,:JWASTAGEDES:,:QTYMAT:,:REMARK:,:VKPQTY:,:P0:,:P1:,:P2:,:P3:,:P4:,:P5:,:P6:,:P7:,:P8:,:P9:,:P10:,:P11:,:P12:,:P13:,:P14:,:P15:,:P16:,:P17:,:P18:,:P19:,:P20:,:P21:,:P22:,:P23:,:P24:,:P25:,:P26:,:P27:,:P28:,:P29:)";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
            }

            Connect2Proxy(or1);
        }
        public DataSet QueryICC_PRULES(DataRow dwData, int option = 1)
        {

           
            switch (option)
            {
                case 1:
                    SResult = QPRULES01(dwData);
                    break;
                case 2:
                    SResult = QPRULES02(dwData);
                    break;
                case 3:
                    SResult = QPRULES03(dwData);
                    break;
                case 9999:
                    SResult = QPRULES04(dwData);
                    break;
                default:
                    break;
            }
             
            return SResult;
        }
        public DataSet QPRULES01(DataRow dwData)
        {

            or1 = OracleDB.CreateCommand(); 
            or1.CommandText = "SELECT * FROM ICC_PRULES WHERE   ROWNID=:ROWNID:"; ;
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData); 
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = "ICC_PRULES";
            return SResult;
        }
        public DataSet QPRULES02(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM ICC_PRULES WHERE ORDERNUM=:ORDERNUM:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1); 
            SResult.Tables[0].TableName = "ICC_PRULES";
            return SResult;
        }
        public DataSet QPRULES03(DataRow dwData)
        {

            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM ICC_PRULES WHERE ARTSTAGE=:ARTSTAGE: AND PLANID=ORDERNUM";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = "ICC_PRULES";
            return SResult;
        }
        public DataSet QPRULES04(DataRow dwData)
        {

            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM ICC_PRULES WHERE PLANID=ORDERNUM";
            SResult = Connect2Proxy(or1); 
            SResult.Tables[0].TableName = "ICC_PRULES";
            return SResult;
        } 
        public DataSet QPRULESVKP(DataRow dwData)
        {

            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM ICC_PRULES WHERE P4=:P4:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = "ICC_PRULES";
            return SResult;
        }
        public DataSet QPRULES05(DataRow dwData)
        {

            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM ICC_PRULES WHERE ORDERNUM=:ORDERNUM: AND  P4=:P4:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = "ICC_PRULES";
            return SResult;
        }
        public DataSet QPRULES06(DataRow dwData)
        {

            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM ICC_PRULES WHERE ORDERNUM IN ( SELECT ORDERNUM FROM ICC_PRULES WHERE   P4=:P4:)";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = "ICC_PRULES";
            return SResult;
        }
        public void DPRULES01(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE FROM ICC_PRULES"
                + " WHERE ROWNID=:ROWNID:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);
        }
        public void DPRULES03(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE FROM ICC_PRULES"
                + " WHERE ORDERNUM=:ORDERNUM:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);
        }
        public void DPRULES02(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE FROM ICC_PRULES";
            Connect2Proxy(or1);
        }
        public void UpdateICC_PRULES(DataRow dwData, int options = 1)
        {
            or1 = OracleDB.CreateCommand();
            UPRULES01(dwData);
        }
        public void UPRULES01(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            
                    or1.CommandText = "UPDATE ICC_PRULES SET ROWNID=:ROWNID:,PLANID=:PLANID:,RGROUP=:RGROUP:,RULEID=:RULEID:,ARTSTAGE=:ARTSTAGE:,ORDERNUM=:ORDERNUM:,ART=:ART:,COLOR=:COLOR:,FINISH=:FINISH:,AUFTYP=:AUFTYP:,QTYEND=:QTYEND:,QTYENDDES=:QTYENDDES:,LEADTIME=:LEADTIME:,DELDATE=:DELDATE:,STARTDATE=:STARTDATE:,UMS=:UMS:,UNITNUM=:UNITNUM:,UNDES=:UNDES:,UNITQTY=:UNITQTY:,UQDES=:UQDES:,TTENDS=:TTENDS:,UENDS=:UENDS:,R01=:R01:,R01DES=:R01DES:,R02=:R02:,R02DES=:R02DES:,F01=:F01:,F01DES=:F01DES:,F02=:F02:,F02DES=:F02DES:,JNUM=:JNUM:,JNUMDES=:JNUMDES:,JWASTGE=:JWASTGE:,JWASTAGEDES=:JWASTAGEDES:,QTYMAT=:QTYMAT:,REMARK=:REMARK:,VKPQTY=:VKPQTY:,P0=:P0:,P1=:P1:,P2=:P2:,P3=:P3:,P4=:P4:,P5=:P5:,P6=:P6:,P7=:P7:,P8=:P8:,P9=:P9:,P10=:P10:,P11=:P11:,P12=:P12:,P13=:P13:,P14=:P14:,P15=:P15:,P16=:P16:,P17=:P17:,P18=:P18:,P19=:P19:,P20=:P20:,P21=:P21:,P22=:P22:,P23=:P23:,P24=:P24:,P25=:P25:,P26=:P26:,P27=:P27:,P28=:P28:,P29=:P29:"
                                   + " WHERE ROWNID=:ROWNID:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                 
            Connect2Proxy(or1);
        }
        public void UPRULES02(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();

            or1.CommandText = "UPDATE ICC_PRULES SET QTYEND=:QTYEND:"
                           + " WHERE ROWNID=:ROWNID:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);

            Connect2Proxy(or1);
        }

    }
}
